package com.medical.patient.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.medical.patient.entity.PatientWalletEntity;
import com.medical.patient.service.PatientWalletService;
import com.medical.common.utils.PageUtils;
import com.medical.common.utils.R;



/**
 * 
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2021-08-19 15:38:09
 */
@RestController
@RequestMapping("patient/patientwallet")
public class PatientWalletController {
    @Autowired
    private PatientWalletService patientWalletService;

    /**
     * 列表
     */

    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = patientWalletService.queryPage(params);

        return R.ok().put("page", page);
    }

    /**
     * 钱包列表
     */
    @RequestMapping("/wallet")
    public R wallet(@PathVariable("userId") String userId){
        PatientWalletEntity patientWalletEntity  = patientWalletService.walletListByUserId(userId);

        return R.ok().put("patientWalletEntity", patientWalletEntity);
    }

    /**
     * 余额展示
     */
    @RequestMapping("/balance/{userId}")
    public R balance(@PathVariable("userId") String userId){
        PatientWalletEntity patientWallet = patientWalletService.balanceByUserId(userId);

        return R.ok().put("patientWallet", patientWallet);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{walletId}")
    public R info(@PathVariable("walletId") Integer walletId){
		PatientWalletEntity patientWallet = patientWalletService.getById(walletId);

        return R.ok().put("patientWallet", patientWallet);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody PatientWalletEntity patientWallet){
		patientWalletService.save(patientWallet);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody PatientWalletEntity patientWallet){
		patientWalletService.updateById(patientWallet);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] walletIds){
		patientWalletService.removeByIds(Arrays.asList(walletIds));

        return R.ok();
    }

}
